package redisKeyDef

import (
	"ToolLibray/mqsmessage"
	"fmt"
	"github.com/zeromicro/go-zero/core/stores/redis"
)

const TenantInitialization = "TenantInitialization" //租户初始化锁
const TenantSyncDictionary = "TenantSyncDictionary" //租户同步字典锁

type RedisKey struct {
	Redis *redis.Redis
}

func NewRedisKey(Redis *redis.Redis) *RedisKey {
	return &RedisKey{
		Redis: Redis,
	}
}

func (r *RedisKey) GetTenantInitialization(TenantId int32) (string, error) {
	value, e := r.Redis.Get(fmt.Sprintf("%s:%d", TenantInitialization, TenantId))

	return value, e
}

func (r *RedisKey) SetTenantInitialization(TenantId int32, value string) error {
	e := r.Redis.Set(fmt.Sprintf("%s:%d", TenantInitialization, TenantId), value)
	return e
}

func (r *RedisKey) GetTenantSyncDictionary(TenantId int32) (string, error) {
	value, e := r.Redis.Get(fmt.Sprintf("%s:%d", TenantSyncDictionary, TenantId))

	return value, e
}

func (r *RedisKey) SetTenantSyncDictionary(TenantId int32, value string) error {
	e := r.Redis.Set(fmt.Sprintf("%s:%d", TenantSyncDictionary, TenantId), value)
	return e
}

// 解锁
func (r *RedisKey) UnlockTenantCopyTempCode() error {

	_, e := r.Redis.Del(mqsmessage.TenantCopyTempCode)
	return e
}
